<?php
function aff_texture( $path , $callback ){

	if ($handle = opendir($path)) {
		echo "<div class=div_thumbContent >";
		echo "<style >
	div.div_thumbContent a{
		float:left;
		margin:5px;
		border:1px solid white;

	}
	div.div_thumbContent a:hover{
		border-color:red;
	}
	div.div_thumbContent img{
	border-width:0px;
	}

	</style>";


		/* This is the correct way to loop over the directory. */
		while (false !== ($entry = readdir($handle))) {
			if( !is_file( $path."/".$entry ))
				continue;

			echo "<a href='#' onclick=\"".$callback."( '".$path."/".$entry."' );return false;\" ><img width='50' height=50 src='".$path."/".$entry."' /></a>";
		}
		echo "</div>";




		closedir($handle);
	}

}



function findPath( $user_id ){
	//// images path for user uploads is:
	//// images/users/... and the b256 user_id written with 5 digit:
	/// exs: 18 is 0/0/18
	/// 300 is 0/255/45
	/// number of user max = 256*256*256 = 16.000 000
	$q1 = floor( $user_id / 256 );
	$Path[ 2 ] = $user_id - 256 * $q1;
	$q2 = floor( $q1 / 256 );
	$Path[ 1 ] = $q1 - 256 * $q2;
	$q3 = floor( $q2 / 256 );
	$Path[ 0 ] = $q2 - 256 * $q3;
	return $Path[ 0 ]."/".$Path[ 1 ]."/".$Path[ 2 ]."/";
	
	
	
	
	

}




